<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
 <canvas id="chart" width="800" height="400" style="background-color: #ccc;"></canvas>
 <script>
  /** @type {HTMLCanvasElement} */ /* 添加canvs相关的语法提示 */
  // 得到canvas标签对象(相当于画布)
  const canvas = document.getElementById('chart')
  // 得到画笔
  const context = canvas.getContext('2d')

  // 绘制线段
  context.moveTo(50, 100)
  context.lineTo(150, 100)
  context.lineTo(100, 300)
  context.lineTo(50, 100)

  // 画出来
  // 描边
  context.strokeStyle = 'blue'
  context.stroke()
  // 填充
  context.fillStyle = 'pink'
  context.fill()


  /* 绘制矩形 */
  context.strokeRect(150, 50, 150, 50)
  context.fillRect(170, 70, 100, 50)

  /* 绘制圆形 */
  context.beginPath()
  context.arc(250, 250, 50, 0, Math.PI/2, true)
  context.stroke()
  context.closePath()

  context.beginPath()
  context.arc(500, 250, 50, 0, Math.PI*2)
  context.fillStyle = '#aa2'
  context.fill()
  context.closePath()

  /* 清除矩形区域 */
  context.clearRect(0, 0, 100, 200)

  /* 绘制文字 */
  context.font = '30px'
  context.textAlign = 'center'
  context.fillText('武汉校区', 10, 40)

 </script>
</body>
</html>